package com.wie.utils;

import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

@Slf4j
public class OkHttpUtil {

    public static String getRequest (String url) throws IOException {
        // 发送 get 请求
        OkHttpClient httpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(url)
                .build();
        Response response = httpClient.newCall(request).execute();
        String result = null;
        if (response.isSuccessful()) {
            result = response.body().string();
        } else {
            log.info("请求失败");
        }
        return result;
    }

}
